package com.zxy.ziems.server.device.controller;

import com.zxy.ziems.server.device.pojo.dto.DevicePropertyAlarmDTO;
import com.zxy.ziems.server.device.pojo.vo.DevicePropertyAlarmVO;
import com.zxy.ziems.server.device.service.DevicePropertyAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集管理-设备-告警配置
 * @author 10348359
 * @create 2024-03-28 10:15
 */
@RestController
@Validated
@RequestMapping("/api")
public class DevicePropertyAlarmController {
    /**
     * 设备-增加告警配置
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/device/alarm/add")
    public void add(@Validated(value = DevicePropertyAlarmDTO.Add.class) @RequestBody DevicePropertyAlarmDTO dto) throws Exception {
        service.add(dto);
    }

    /**
     * 设备-更新告警配置
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/device/alarm/update")
    public void update(@Validated(value = DevicePropertyAlarmDTO.Update.class) @RequestBody DevicePropertyAlarmDTO dto) throws Exception {
        service.update(dto);
    }

    /**
     * 设备-删除告警配置
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/device/alarm/delete")
    public void delete(@Validated(value = DevicePropertyAlarmDTO.Delete.class) @RequestBody DevicePropertyAlarmDTO dto) throws Exception {
        service.deleteById(dto.getId());
    }

    /**
     * 设备-查询告警配置列表
     * @param deviceId 设备类型
     * @return
     */
    @GetMapping("/device/collector/device/alarm/list")
    public List<DevicePropertyAlarmVO> list(@RequestParam(value = "deviceId", required = true) String deviceId) throws Exception {
        return service.viewListByDeviceId(deviceId);
    }

    private DevicePropertyAlarmService service;

    @Autowired
    public void setService(DevicePropertyAlarmService devicePropertyAlarmService) {
        this.service = devicePropertyAlarmService;
    }
}
